001 /* EVolve - an Extensible Software Visualization Framework
002 * Copyright (C) 2001-2002 Qin Wang
003 *
004 * This library is free software; you can redistribute it and/or
005 * modify it under the terms of the GNU Library General Public
006 * License as published by the Free Software Foundation; either
007 * version 2 of the License, or (at your option) any later version.
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Library General Public License for more details.
013 *
014 * You should have received a copy of the GNU Library General Public
015 * License along with this library; if not, write to the
016 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
017 * Boston, MA 02111-1307, USA.
018 */
019
020 /*
021 * EVolve is distributed at http://www.sable.mcgill.ca/EVolve/
022 */
023
024 package EVolve;
025
026 import EVolve.visualization.*;
027 import EVolve.util.overlappers.OverlapVisualization;
028 import java.awt.*;
029 import java.awt.event.*;
030 import javax.swing.*;
031 import javax.swing.event.*;
032
033 public class Window extends JInternalFrame {
034 private Visualization visualization;
035 private OverlapVisualization oVisual;
036
037 public Window(OverlapVisualization oVisual) {
038 super("Overlapped visualization",true,true,true,true);
039 this.visualization = null;
040 this.oVisual = oVisual;
041 this.getContentPane().setLayout(new BorderLayout());
042 this.getContentPane().add(oVisual.getPanel(), BorderLayout.CENTER);
043
044 this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
045 this.addInternalFrameListener(new InternalFrameAdapter() {
046 public void internalFrameClosing(InternalFrameEvent e) {
047 cleanup();
048 }
049 });
050 }
051
052 public Window(Visualization visualization) {
053 super(visualization.getName() + " - " + visualization.getSubjectDefinition().getName(), true, true, true, true);
054
055 this.visualization = visualization;
056 this.getContentPane().setLayout(new BorderLayout());
057 this.getContentPane().add(visualization.getPanel(), BorderLayout.CENTER);
058
059 this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
060 this.addInternalFrameListener(new InternalFrameAdapter() {
061 public void internalFrameClosing(InternalFrameEvent e) {
062 unregisterLinkedViz();
063 cleanup();
064 }
065 });
066 }
067
068 public Visualization getVisualization() {
069 return visualization;
070 }
071
072 private void cleanup() {
073 Scene.getUIManager().removeWindow(this);
074 if (visualization!=null)
075 visualization.cleanup();
076 else
077 oVisual.cleanup();
078 }
079
080 private void unregisterLinkedViz() {
081 Scene.getToolsManager().getLinkedVisualizationRunner().unregisterLinkedViz(visualization);
082 }
083
084 private void unregisterOverlappedViz() {
085 Scene.getToolsManager().getOverlapVisualizationRunner().unregisterOverlappedViz(visualization);
086 }
087
088 }